//
//  SJHomePageView.m
//  SJPay
//
//  Created by 凯朱 on 2024/11/26.
//

#import "SJHomePageView.h"
#import "SJAuthVC.h"
@implementation SJHomePageView
-(void)awakeFromNib{
    [super awakeFromNib];
    _bgView3.layer.cornerRadius = 15;
    _bgView3.layer.masksToBounds = YES;
    
    _btn1.layer.cornerRadius = 22.5;
    _btn1.tag = 1;
    _btn1.layer.masksToBounds = YES;
    [_btn1 setBackgroundImage:[UIImage imageWithColor:KClearColor] forState:UIControlStateNormal];
    [_btn1 setBackgroundImage:[UIImage imageWithColor:kHexColor(@"#5E80FE")] forState:UIControlStateSelected];
    [_btn1 setTitleColor:KColor_B forState:UIControlStateNormal];
    [_btn1 setTitleColor:KWhiteColor forState:UIControlStateSelected];
    
    _btn2.layer.cornerRadius = 22.5;
    _btn2.layer.masksToBounds = YES;
    [_btn2 setBackgroundImage:[UIImage imageWithColor:KClearColor] forState:UIControlStateNormal];
    [_btn2 setBackgroundImage:[UIImage imageWithColor:kHexColor(@"#5E80FE")] forState:UIControlStateSelected];
    _btn2.tag = 2;
    [_btn2 setTitleColor:KColor_B forState:UIControlStateNormal];
    [_btn2 setTitleColor:KWhiteColor forState:UIControlStateSelected];
    
    _btn3.layer.cornerRadius = 22.5;
    _btn3.layer.masksToBounds = YES;
    [_btn3 setBackgroundImage:[UIImage imageWithColor:KClearColor] forState:UIControlStateNormal];
    [_btn3 setBackgroundImage:[UIImage imageWithColor:kHexColor(@"#5E80FE")] forState:UIControlStateSelected];
    _btn3.tag = 3;
    [_btn3 setTitleColor:KColor_B forState:UIControlStateNormal];
    [_btn3 setTitleColor:KWhiteColor forState:UIControlStateSelected];
   
    
    _sureBtn.layer.cornerRadius = 25;
    _sureBtn.layer.masksToBounds = YES;
    
    _tipLbl2.text = kLocalString(@"最高可借额度");
    _tipLbl3.text = kLocalString(@"Unable to apply for a loan under the age of 18");
    [_sureBtn setTitle:kLocalString(@"立即申请") forState:UIControlStateNormal];
    _titleLbl.text = kLocalString(@"Fácil Préstamo");
    _tipLbl4.text = kLocalString(@"申请简单");
    _tipLbl5.text = kLocalString(@"3步轻松贷款");
    _tipLbl6.text = kLocalString(@"极速放款");
    _tipLbl7.text = kLocalString(@"最快5分钟到账");
    
    _btn1.selected = YES;
    _curBtn = _btn1;
    CGFloat centerX = self.width/2;
    _curBtn.centerX = centerX;
    _btn2.centerX = centerX+55;
    _btn3.centerX = centerX+110;
}

- (IBAction)btnAction:(UIButton *)sender {
    if (_curBtn == sender) {
        return;
    }
    
    sender.selected = YES;
    _curBtn.selected = NO;
    _curBtn = sender;
    CGFloat centerX = self.width/2;
    [UIView animateWithDuration:0.25 animations:^{
        if (self->_curBtn == self->_btn1) {
            self->_curBtn.centerX = centerX;
            self->_btn2.centerX = centerX+55;
            self->_btn3.centerX = centerX+110;
        }else if(self->_curBtn == self->_btn2){
            self->_curBtn.centerX = centerX;
            self->_btn1.centerX = centerX-55;
            self->_btn3.centerX = centerX+55;
        }else{
            self->_curBtn.centerX = centerX;
            self->_btn1.centerX = centerX-110;
            self-> _btn2.centerX = centerX-55;
        }
    }];
    if (self.btnBlock) {
        self.btnBlock(_curBtn.tag);
    }
}

- (IBAction)sureAction:(id)sender {
    if (kIsTourst) {
        [ZCTool pushToLoginVc];
        return;
    }
    SJAuthVC *vc = [SJAuthVC new];
    kWeakSelf(self);
    [vc setApplyFinish:^(NSInteger btnIndex) {
        [weakself applyFinishAction];
    }];
    [[ZCTool getCurrentUIVC].navigationController pushViewController:vc animated:YES];
    
}

-(void)applyFinishAction{
    MainTabBarController *tab = [MainTabBarController new];
    [UIApplication sharedApplication].keyWindow.rootViewController = tab;
}


@end
